<?php

/**
 * PDO SAFE
 * @author HxBreak
 * @Description: todo
 * @Date 2017年6月7日 上午11:37:24 
 * @File hopetype.php
 */

include 'vendor/autoload.php';
include 'common.php';

use Base64Url\Base64Url;

$username = $_COOKIE['username'];
$token = $_COOKIE['token'];
$description= $_REQUEST['type'];



$dbc = pdo_root_connect();
$stmt = $dbc->prepare('select * from userinfo where username=:username and token=:token');
$stmt->bindParam(':username', $username);
$stmt->bindParam(':token', $token);

$stmt->execute();

if($stmt->rowCount() > 0)
{
	$encode_d = Base64Url::encode($description);
	if($username == 'freeparty' || strcasecmp($username, 'hxbreak') == 0)
	{
		$insertType = $dbc->prepare('insert into hopetype (username, description, addtime) values
		(:username, :description, unix_timestamp(now()))');
		$insertType->bindParam(':username', $username);
		$insertType->bindParam(':description', $encode_d);
		$insertType->execute();
//		$result2 = mysql_query("insert into hopetype (username, description, addtime) values ('$username', '$type', '$time')");
//		safelog($username, 'INSERT_H_TYPE', $conn);
		if($insertType->rowCount() > 0){
			$errorcode = 1;
		}else{
			$errorcode = 7;//插入失败
		}
	}else
	{
		//后面可能会进行调整
		$errorcode = 6;//权限不足
	}

}else
{
	$errorcode = 5;
}
echo json_encode(array('errorcode'=>$errorcode));
?>